package client.comm.baoding.adapter

import android.view.View
import androidx.recyclerview.widget.DiffUtil
import client.comm.baoding.R
import client.comm.baoding.api.bean.HangOrderRecord
import client.comm.baoding.databinding.LayoutItemSgGuadBinding
import client.comm.commlib.base.BasePagingAdapter
import client.comm.commlib.base.PagingViewHoder
import com.bumptech.glide.RequestManager
import com.google.gson.Gson

class MyGuaDAndSgAdapter(val mImgLoader: RequestManager) :
    BasePagingAdapter<HangOrderRecord.Order>(object :

        DiffUtil.ItemCallback<HangOrderRecord.Order>() {
        val gson = Gson()
        override fun areItemsTheSame(
            oldItem: HangOrderRecord.Order,
            newItem: HangOrderRecord.Order
        ): Boolean {
            return true
        }

        override fun areContentsTheSame(
            oldItem: HangOrderRecord.Order,
            newItem: HangOrderRecord.Order
        ): Boolean {
            return gson.toJson(oldItem).equals(gson.toJson(newItem))
        }
    }) {

    var isShowCancle = false
    var isFinish = false

    var cOrder: ((b: HangOrderRecord.Order) -> Unit)? = null

    fun cancleOrder(b: HangOrderRecord.Order) {
        cOrder?.invoke(b)
    }

    var guaMaiCli: ((b: HangOrderRecord.Order, type: Int) -> Unit)? = null

    // 买
    fun guaMai(b: HangOrderRecord.Order, type: Int) {
        guaMaiCli?.invoke(b,type)
    }

    override fun bindItem(holder: PagingViewHoder, t: Any) {
        val binding = holder.binding as LayoutItemSgGuadBinding
        val bean = t as HangOrderRecord.Order
        binding.bean = bean
        binding.event = this

        if (isShowCancle) {
            binding.tvStatus.visibility = View.VISIBLE
            binding.finisWrap.visibility = View.GONE

        }

        if (isFinish) {
            binding.stateStr.visibility = View.VISIBLE
            binding.finisWrap.visibility = View.GONE
        }
//        val time = bean.create_time.substring(5, bean.create_time.length - 3)
//        binding.time = time
    }

    override fun getItemLayout(): Int {
        return R.layout.layout_item_sg_guad
    }

}